package com.gyf.bos.web.action;

import com.gyf.bos.model.PageBean;
import com.gyf.bos.model.Staff;
import com.gyf.bos.service.IStaffService;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletResponse;

public class StaffAction extends BaseAction<Staff> {

    @Autowired
    private IStaffService staffService;
    @Override
    public String save() {
        System.out.println(getModel());
        staffService.save(getModel());
        return SUCCESS;
    }

    @Override
    public String update() {
        return null;
    }

    @Override
    public String delete() {
        return null;
    }

    @Override
    public String list() {


        return null;
    }
    //========================分页查询返回json数据=================
    private int page;
    private int rows;

    public void setPage(int page) {
        this.page = page;
    }

    public void setRows(int rows) {
        this.rows = rows;
    }
    public void pageQuery(){
        PageBean<Staff> pb = new PageBean<Staff>();
        pb.setCurrentPage(page);
        pb.setPageSize(rows);
        DetachedCriteria dc = DetachedCriteria.forClass(Staff.class);
        pb.setDetachedCriteria(dc);

        //2通过service查询分页数据
        staffService.pageQuery(pb);

        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("text/json;charset=UTF-8");
//
//        //3.将分页数据封装成固定格式的json数据
//        JsonConfig jc = new JsonConfig();
//        jc.setExcludes(new String[]{"currentPage","pageSize","detachedCriteria"});
//        JSONObject jb = JSONObject.fromObject(pageBean,jc);
//        response.getWriter().print(jb.toString());
    }
}


























